<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
</head>
<body>
<div>
    <p><label>用户名：</label><input type="text" id="username" placeholder="用户名"/></p>
    <p><label>密码：</label><input type="password" id="password" placeholder="密码"/></p>
    <p><button id="btn">登录</button></p>
</div>
</body>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script>
    $("#btn").click(function () {
        var username = $("#username").val();
        var password = $("#password").val();
        $.ajax({
            url:'/login',
            type:'post',
            data:{
                'username':username,
                'password':password
            },
            dataType:'json',
            success:function (res) {
                console.log(JSON.stringify(res));
                if (res.code == '0') {
                    localStorage.setItem('token', res.data);
                    localStorage.setItem('username', username);
                    location.href = '/index.html';
                }
            }
        });
    });
</script>
</html>